<?php
class Admin_Form_Product extends Zend_Form
{
    public function init()
    {
        $this->setName("admin");
        
        $id = new Zend_Form_Element_Hidden('id');
        $id->addFilter('Int');
        
        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('Tiêu đề (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $title->setAttrib('size', 60);
        
        $createD = new Zend_Form_Element_Text('createDate');
        $createD->setLabel('Ngày Tạo (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $createD->setAttrib('size', 60)->setAttrib('class','datepicker2')->setAttrib('placeholder','dd/mm/yy');
        $startD = new Zend_Form_Element_Text('startDate');
        $startD->setLabel('Ngày Bắt Đầu (*)')->addFilter('StripTags')->addFilter('StringTrim');
        $startD->setAttrib('size', 60)->setAttrib('class','datepicker2')->setAttrib('placeholder','dd/mm/yy');
        $endD = new Zend_Form_Element_Text('endDate');
        $endD->setLabel('Ngày Kết Thúc (*)')->addFilter('StripTags')->addFilter('StringTrim');
        $endD->setAttrib('size', 60)->setAttrib('class','datepicker2')->setAttrib('placeholder','dd/mm/yy');                                        

        $con = new Zend_Form_Element_Textarea('content');
        $con->setLabel('Nội dung (*)')->setRequired(true)->addValidator('NotEmpty',false,array('messages'=>'Thêm mô tả cho sản phẩm để ....'));
        $con->setAttrib('rows', 10);
        
        $price = new Zend_Form_Element_Text('price');
        $price->setLabel('Giá (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty')->addFilter('Int');                                    
                        
        $human = new Zend_Form_Element_Select('human');
        $human->setLabel('Bạn là');                        
        $configCar= new Zend_Config_Ini(CONFIG_PATH.'/human.ini', APPLICATION_ENV);
        $huL=$configCar->human->toArray();        
        foreach($huL as $k => $v){
            $human->addMultiOption($k,$v);    
        }
         
        $tran = new Zend_Form_Element_Select('transaction');
        $tran->setLabel('Bạn cần');                        
        $configTran= new Zend_Config_Ini(CONFIG_PATH.'/transaction.ini', APPLICATION_ENV);
        $tranL=$configTran->transaction->toArray();        
        foreach($tranL as $k => $v){
            $tran->addMultiOption($k,$v);    
        }         
                
        $user = new Zend_Form_Element_Select('userId');
        $user->setLabel('Tài khoản sở hữu');          
        $modelU = new Admin_Model_User();
        $userL = $modelU->getAllData();
        $user->addMultiOption('0','--- Tin tự do ---');
        foreach($userL as $u) $user->addMultiOption($u['id'],$u['email']);                                                                                            
        
        $item = new Zend_Form_Element_Select('itemId');
        $item->setLabel('Thuộc danh mục sản phẩm');          
        $modeC = new Admin_Model_Productcat();
        $modelI = new Admin_Model_Productitem();        
        $catL = $modeC->getAllData();        
        foreach($catL as $o){
            $item->addMultiOption('cat-'.$o->id,'Cấp 1 - '.$o->name);
            $arrT[] = 'cat-'.$o->id;                         
            $itemL = $modelI->getDataByCat($o->id);            
            foreach($itemL as $t){
                $item->addMultiOption($t->id,$t->name);                  
            }      
        } 
        $item->setAttrib('disable',$arrT);
        
        $area = new Zend_Form_Element_Select('areaId');
        $area->setLabel('Khu vực');        
        $modelA = new Admin_Model_Area();
        $areaL = $modelA->getAllData();        
        foreach($areaL as $o) $area->addMultiOption($o['id'],$o['name']);
        
        $pho =new Zend_Form_Element_File('photo');                        
        $pho->setLabel('Hình Ảnh - ');                                  
        $pho->addValidator('Extension',true,array('jpg','gif','png'),'picture');                 
        $pho->addValidator('Size',true,array('min'=>'0KB','max'=>'300KB'),'picture');
        $pho->setMultiFile(7);        
                        
        // submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id','submitbutton');
        $submit->setAttrib('class',"button medium");
        $submit->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper');
        
        $status = new Zend_Form_Element_Select('status');
        $status->setLabel('Tình trạng');                                                
        $status->addMultiOption('1','Chưa duyệt');    
        $status->addMultiOption('2','Đã duyệt');
        $status->addMultiOption('3','Đã khoá');
        
        $contact = new Zend_Form_Element_Text('contact');
        $contact->setLabel('Người liên hệ (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');        
        
        $mobile = new Zend_Form_Element_Text('mobile');
        $mobile->setLabel('Di động(*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')
            ->addValidator('NotEmpty')->addValidator('Digits',false,array('messages'=>'Số điện thoại không hợp lệ'))->addValidator('stringLength', false, array(8, 11,'messages'=>'Số điện thoại chưa chính xác'));
        
        $emailCont = new Zend_Form_Element_Text('emailCont');
        $emailCont->setLabel('Email')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('EmailAddress');                
                
        $addressCont = new Zend_Form_Element_Text('addressCont');
        $addressCont->setLabel('Địa chỉ')->addFilter('StripTags')->addFilter('StringTrim');
        
        $priceAd = new Zend_Form_Element_Text('priceAd');
        $priceAd->setLabel('Phí đăng tin')->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('readonly','true');
        
        $type = new Zend_Form_Element_Select('type');
        $type->setLabel('Loại tin');                                                
        $type->addMultiOption('no','Tin thường');    
        $type->addMultiOption('vi','Tin vip');
        
        $reset = new Zend_Form_Element_Reset('reset');
        $reset->setAttrib('id','submitbutton');
        $reset->setAttrib('class',"button medium");
        $reset->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper');                
                
        // add elements to form
        $this->addElements(array (
            $id, $human, $tran, $type, $user, $area, $item, $title, $createD, $startD, $endD, $priceAd, $con, $price, $pho, $contact, $mobile, $emailCont, $addressCont,          
            $status, $submit, $reset
        ));   
                                     
    }
}

